load("//bazel:mongo_src_rules.bzl", "idl_generator", "mongo_cc_library", "mongo_cc_unit_test")

package(default_visibility = ["//visibility:public"])

exports_files(
    glob([
        "*.h",
        "*.cpp",
    ]),
)

idl_generator(
    name = "exception_util_gen",
    src = "exception_util.idl",
)

mongo_cc_library(
    name = "exception_util",
    srcs = [
        "exception_util.cpp",
        ":exception_util_gen",
    ],
    hdrs = [
        "exception_util.h",
    ],
    deps = [
        "//src/mongo/db:server_base",
        "//src/mongo/db:server_options_servers",
        "//src/mongo/db/commands:server_status_core",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db/query/query_stats",
        "//src/mongo/db/storage:recovery_unit_base",  # TODO(SERVER-93876): Remove.
        "//src/mongo/util:fail_point",  # TODO(SERVER-93876): Remove.
        "//src/mongo/util:log_and_backoff",
    ],
)

mongo_cc_library(
    name = "lock_manager",
    srcs = [
        "cond_var_lock_grant_notification.cpp",
        "d_concurrency.cpp",
        "fill_locker_info.cpp",
        "lock_manager.cpp",
        "lock_manager_defs.cpp",
        "lock_request_list.h",
        "lock_stats.cpp",
        "locker.cpp",
        "replication_state_transition_lock_guard.cpp",
        "resource_catalog.cpp",
    ],
    hdrs = [
        "cond_var_lock_grant_notification.h",
        "d_concurrency.h",
        "fill_locker_info.h",
        "lock_manager.h",
        "lock_manager_defs.h",
        "lock_stats.h",
        "locker.h",
        "replication_state_transition_lock_guard.h",
        "resource_catalog.h",
        "//src/mongo:core_headers",
    ],
    no_undefined_ref_DO_NOT_USE = False,
    deps = [
        "//src/mongo/db:server_base",
        "//src/mongo/db/admission:execution_admission_context",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db/admission:ticketholder_manager",
        "//src/mongo/db/concurrency:flow_control_ticketholder",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db/stats:counter_ops",
        "//src/mongo/db/storage/key_string",
        "//src/mongo/util:background_job",  # TODO(SERVER-93876): Remove.
        "//src/mongo/util:fail_point",  # TODO(SERVER-93876): Remove.
        "//src/mongo/util/concurrency:spin_lock",  # TODO(SERVER-93876): Remove.
        "//src/mongo/util/concurrency:ticketholder",  # TODO(SERVER-93876): Remove.
    ],
)

mongo_cc_library(
    name = "flow_control_ticketholder",
    srcs = [
        "flow_control_ticketholder.cpp",
    ],
    hdrs = [
        "//src/mongo/bson:bson_duration.h",
        "//src/mongo/bson:bson_time_support.h",
        "//src/mongo/bson/mutable:api.h",
        "//src/mongo/bson/mutable:element_hdrs",
        "//src/mongo/client:connection_string_hdrs",
        "//src/mongo/crypto:hash_block.h",
        "//src/mongo/db:basic_types.h",
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db:baton_hdrs",
        "//src/mongo/db:client_hdrs",
        "//src/mongo/db:cluster_role_hdrs",
        "//src/mongo/db:database_name_hdrs",
        "//src/mongo/db:database_name_reserved.def.h",
        "//src/mongo/db:jsobj.h",
        "//src/mongo/db:logical_time_hdrs",
        "//src/mongo/db:namespace_string_hdrs",
        "//src/mongo/db:namespace_string_reserved.def.h",
        "//src/mongo/db:operation_context_hdrs",
        "//src/mongo/db:operation_id_hdrs",
        "//src/mongo/db:read_write_concern_provenance_base_gen",
        "//src/mongo/db:read_write_concern_provenance_hdrs",
        "//src/mongo/db:record_id.h",
        "//src/mongo/db:record_id_helpers_hdrs",
        "//src/mongo/db:server_options_hdrs",
        "//src/mongo/db:server_parameter_hdrs",
        "//src/mongo/db:server_parameter_with_storage_hdrs",
        "//src/mongo/db:service_context_hdrs",
        "//src/mongo/db:tenant_id_hdrs",
        "//src/mongo/db:write_concern_gen",
        "//src/mongo/db:write_concern_idl_hdrs",
        "//src/mongo/db:write_concern_options_hdrs",
        "//src/mongo/db/admission:execution_admission_context_hdrs",
        "//src/mongo/db/auth:action_set_hdrs",
        "//src/mongo/db/auth:action_type_gen",
        "//src/mongo/db/auth:action_type_hdrs",
        "//src/mongo/db/auth:auth_name_hdrs",
        "//src/mongo/db/auth:privilege_hdrs",
        "//src/mongo/db/auth:resolve_role_option.h",
        "//src/mongo/db/auth:resource_pattern_hdrs",
        "//src/mongo/db/auth:restriction_environment.h",
        "//src/mongo/db/auth:role_name.h",
        "//src/mongo/db/auth:user_name.h",
        "//src/mongo/db/auth:validated_tenancy_scope_factory_hdrs",
        "//src/mongo/db/auth:validated_tenancy_scope_hdrs",
        "//src/mongo/db/catalog:clustered_collection_options_gen",
        "//src/mongo/db/concurrency:cond_var_lock_grant_notification.h",
        "//src/mongo/db/concurrency:fast_map_noalloc.h",
        "//src/mongo/db/concurrency:flow_control_ticketholder.h",
        "//src/mongo/db/concurrency:lock_manager_defs.h",
        "//src/mongo/db/concurrency:lock_stats.h",
        "//src/mongo/db/concurrency:locker.h",
        "//src/mongo/db/exec:collection_scan_common.h",
        "//src/mongo/db/exec/document_value:document_hdrs",
        "//src/mongo/db/exec/document_value:document_internal.h",
        "//src/mongo/db/exec/document_value:document_metadata_fields_hdrs",
        "//src/mongo/db/exec/document_value:value_hdrs",
        "//src/mongo/db/exec/document_value:value_internal.h",
        "//src/mongo/db/index_builds:index_builds.h",
        "//src/mongo/db/index_builds:resumable_index_builds_gen",
        "//src/mongo/db/pipeline:field_path_hdrs",
        "//src/mongo/db/query:explain_options_hdrs",
        "//src/mongo/db/query:explain_verbosity_gen",
        "//src/mongo/db/query:record_id_bound.h",
        "//src/mongo/db/query/collation:collation_spec.h",
        "//src/mongo/db/query/collation:collator_interface_hdrs",
        "//src/mongo/db/query/datetime:date_time_support_hdrs",
        "//src/mongo/db/query/query_shape:serialization_options_hdrs",
        "//src/mongo/db/repl:optime_hdrs",
        "//src/mongo/db/repl:read_concern_gen",
        "//src/mongo/db/repl:read_concern_idl_hdrs",
        "//src/mongo/db/repl:read_concern_level.h",
        "//src/mongo/db/session:logical_session_id_gen",
        "//src/mongo/db/session:logical_session_id_hdrs",
        "//src/mongo/db/session:logical_session_id_helpers_hdrs",
        "//src/mongo/db/sorter:sorter_gen",
        "//src/mongo/db/storage:compact_options.h",
        "//src/mongo/db/storage:key_format.h",
        "//src/mongo/db/storage:record_data.h",
        "//src/mongo/db/storage:record_store_hdrs",
        "//src/mongo/db/storage:recovery_unit_hdrs",
        "//src/mongo/db/storage:snapshot.h",
        "//src/mongo/db/storage:storage_engine.h",
        "//src/mongo/db/storage:storage_stats.h",
        "//src/mongo/db/storage:temporary_record_store.h",
        "//src/mongo/db/storage:write_unit_of_work_hdrs",
        "//src/mongo/idl:command_generic_argument_hdrs",
        "//src/mongo/idl:idl_parser_hdrs",
        "//src/mongo/platform:atomic_proxy.h",
        "//src/mongo/platform:visibility.h",
        "//src/mongo/rpc:message_hdrs",
        "//src/mongo/rpc:op_msg_hdrs",
        "//src/mongo/transport:session_hdrs",
        "//src/mongo/transport:session_id.h",
        "//src/mongo/util:headers",
        "//src/mongo/util/concurrency:headers",
        "//src/mongo/util/net:headers",
        "//src/mongo/util/version:releases_header",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/crypto:sha256_block",
        "//src/mongo/db/stats:counter_ops",
        "//src/mongo/db/storage:damage_vector",
        "//src/mongo/db/storage:ident",
        "//src/mongo/util:secure_compare_memory",
    ],
)

mongo_cc_library(
    name = "deferred_writer",
    srcs = [
        "deferred_writer.cpp",
    ],
    hdrs = [
        "deferred_writer.h",
    ],
    deps = [
        "//src/mongo/db:dbhelpers",
        "//src/mongo/db:server_base",
        "//src/mongo/db:shard_role",
        "//src/mongo/db/catalog:catalog_helpers",
        "//src/mongo/db/concurrency:exception_util",
        "//src/mongo/util/concurrency:thread_pool",
    ],
)

mongo_cc_unit_test(
    name = "exception_util_test",
    srcs = [
        "exception_util_test.cpp",
    ],
    tags = [
        "mongo_unittest_first_group",
        "server-programmability",
    ],
    deps = [
        ":exception_util",
        "//src/mongo/db:service_context_d_test_fixture",
        "//src/mongo/transport:transport_layer_mock",
    ],
)

mongo_cc_unit_test(
    name = "lock_manager_test",
    srcs = [
        "fast_map_noalloc_test.cpp",
        "fill_locker_info_test.cpp",
        "lock_manager_test.cpp",
        "lock_manager_test_help.h",
        "lock_stats_test.cpp",
        "locker_test.cpp",
        "resource_catalog_test.cpp",
    ],
    tags = ["mongo_unittest_first_group"],
    deps = [
        ":exception_util",
        ":lock_manager",
        "//src/mongo/db:service_context_non_d",
        "//src/mongo/db:service_context_test_fixture",
        "//src/mongo/db/auth:authmocks",
        "//src/mongo/db/query/query_stats",
        "//src/mongo/transport:transport_layer_common",
        "//src/mongo/transport:transport_layer_mock",
    ],
)
